package com.xjc.business.controller.colladmin;

import com.xjc.business.entity.po.coladmin.AssociateClassAdminPo;
import com.xjc.business.entity.po.coladmin.ClassPo;
import com.xjc.business.entity.vo.coladmin.ClassVo;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.service.ClazzsService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 徐锦程
 * 时间:2025-01-29 15:51
 */
@RestController("coll_admin_class_controller")
@RequestMapping("/college_admin/class")
public class ClassController {

    @Autowired
    ClazzsService clazzsService;

    /**
     * 分页查询班级列表
     * @param pageSize 每页显示条数
     * @param currentPage 当前页码
     * @param collegeId 学院id
     * @param majorId 专业id
     * @param classAdminId 辅导员id
     * @return 数据
     */
    @GetMapping("/page/{pageSize}/{currentPage}")
    public Result<PageVo<ClassVo>> getClassPage(
            @PathVariable(value = "pageSize",required = false) Integer pageSize,
            @PathVariable(value = "currentPage",required = false) Integer currentPage,
            Integer collegeId,
            Integer majorId,
            Integer classAdminId
    ){
        if(pageSize == null || pageSize <= 0){
            pageSize = 10;
        }
        if(currentPage == null || currentPage <= 0){
            currentPage = 1;
        }

        if (majorId == null){
            majorId = -1;
        }

        if (classAdminId == null){
            classAdminId = -1;
        }

        if( collegeId == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return clazzsService.getClassPage(pageSize,currentPage,collegeId,majorId,classAdminId);
    }

    /**
     * 添加班级
     * @param classPo 班级信息
     * @return 反馈
     */
    @PostMapping("/add")
    public Result<String> addClass(@RequestBody(required = false) ClassPo classPo){
        if (classPo == null || classPo.getMajorId() == null || classPo.getNum() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return clazzsService.addClass(classPo);
    }

    /**
     * 分配管理员
     * @param associateClassAdminPo 管理员信息
     * @return 反馈
     */
    @PostMapping("/associate_admin")
    public Result<String> associateClassAdmin(@RequestBody(required = false)AssociateClassAdminPo associateClassAdminPo){
        if (associateClassAdminPo == null || associateClassAdminPo.getAdminId() == null || associateClassAdminPo.getClassId() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return clazzsService.associateClassAdmin(associateClassAdminPo);
    }
}
